package com.beilang.base.codelookup.model;

import com.beilang.base.core.model.BaseModel;

/**
 * Data Container for code lookup.
 */
public class CodeModel extends BaseModel implements Cloneable
{
    /**
	 * 
	 */
	private static final long serialVersionUID = -2514771455358373332L;
	private String codeId;
    private String codeDesc;
    private boolean active;
    private boolean assigned;

    public boolean isAssigned() {
        return assigned;
    }

    public void setAssigned(boolean assigned) {
        this.assigned = assigned;
    }

    /**
     * Create an instance of <code>CodeTO</code>
     */
    public CodeModel() {}

    /**
     * Create an instance of <code>CodeTO</code> given the code Id, code description and active indicator.
     * @param codeId    code Id
     * @param codeDesc  code description
     * @param active    <code>true</code> to indicate code is active or valid;
     *                  <code>false</code> otherwise
     */
    public CodeModel(String codeId, String codeDesc, boolean active) {
        this.codeId = codeId;
        this.codeDesc = codeDesc;
        this.active = active;
    }

    /**
     * Return the code Id.
     * @return the code Id
     */
    public String getCodeId() {
        return codeId;
    }

    /**
     * Set the code Id.
     * @param codeId the code Id
     */
    public void setCodeId(String codeId) {
        this.codeId = codeId;
    }

    /**
     * Get the code description
     * @return  the code description
     */
    public String getCodeDesc() {
        return codeDesc;
    }

    /**
     * Set the code description
     * @param codeDesc the code description
     */
    public void setCodeDesc(String codeDesc) {
        this.codeDesc = codeDesc;
    }

    /**
     * Indicate whether the code is active or valid
     * @return <code>true</code> if the code is active or valid;
     *         <code>false</code> otherwise
     */
    public boolean isActive() {
        return active;
    }

    /**
     * Indicate if the code is active
     * @param active <code>true</code> if the code is active or valid;
     *               <code>false</code> otherwise
     */
    public void setActive(boolean active) {
        this.active = active;
    }

    /**
     * Return the code description.
     * If the code is inactive or invalid, the code description is prefixed with "* " and postfixed with " *".
     * <p>
     * For example:
     * <br>
     * <b>&nbsp;&nbsp;&nbsp;* Slovak Federal Republic * </b>
     * @return the code description;
     *         if the code is inactive, the code descriptio is prefixed with "* " and postfixed with " *"
     */
    public String getCodeDisplayDesc() {
        String dispDesc = codeDesc;
        if (! isActive()) {
            dispDesc = "* " + codeDesc + " *";
        }
        return dispDesc;
    }
    
    /**
     * Return true if both <code>CodeTO</code> objects have the same 
     * <code>codeId</code>. 
     */
    public boolean equals(Object obj) {
    	boolean equal = false;
    	if (obj instanceof CodeModel) {
    		CodeModel codeTO = (CodeModel)obj;
    		if (codeTO.getCodeId().equals(codeId)) {
    			equal = true;
    		}
    	}
    	return equal;
    }
    
    public String toString() {
        StringBuffer buf = new StringBuffer("CodeId[");
        buf.append(codeId);
        buf.append("] CodeDesc[");
        buf.append(codeDesc);
        buf.append("] active[");
        buf.append(active);
        buf.append("].");
        return buf.toString();
    }
    
    public Object clone() {
    	return new CodeModel(this.codeId, this.codeDesc, this.active);
    }
}
